package com.fhz.a1911;

import android.content.Context;
import android.content.SharedPreferences;

import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;

/**
 * 时间:2022/5/20
 *
 * @author msfeng
 * 简述: 用来帮助创建viewmodel对象的
 */
public class MyViewModelFactory implements ViewModelProvider.Factory {

    @NonNull
    @Override
    public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
        SharedPreferences fen = App.context.getSharedPreferences("fen", Context.MODE_PRIVATE);
        int number = fen.getInt("number", 2);
        return (T) new MyViewModel(number);
    }
}

